package com.cby.widget.sample

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.cby.widget.sample.bubblenavigation.BubbleNavMainActivity
import com.cby.widget.sample.fragments.*
import com.cby.widget.sample.recyclerview.RecyclerAutoDeleteFragment

class MainActivity : AppCompatActivity() {

    private lateinit var recyclerView: RecyclerView

    private val itemList = mutableListOf<MainBean>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        recyclerView = findViewById(R.id.recycler_view)
        recyclerView.layoutManager = LinearLayoutManager(this@MainActivity)
        initData()
        val adapter = MainAdapter()
        adapter.addData(itemList)
        recyclerView.adapter = adapter
    }

    /**
     * 设置列表数据
     */
    private fun initData() {
        itemList.add(createMainBean(BlurFragment::class.java))
        itemList.add(createMainBean(BlurMaskFragment::class.java))
        itemList.add(createMainBean(PathClockFragment::class.java))
        itemList.add(createMainBean(ProgressBarFragment::class.java))
        itemList.add(createMainBean(IndicatorFragment::class.java))
        itemList.add(createMainBean(RecyclerAutoDeleteFragment::class.java))
        itemList.add(createMainBean(BubbleNavMainActivity::class.java))
        itemList.add(createMainBean(HtmlTextViewFragment::class.java))
    }

    /**
     * [MainBean]的对象创建，通用方法
     * @param clz Class<*>
     * @return MainBean
     */
    private fun createMainBean(clz: Class<*>) = run { MainBean(clz.simpleName, clz.name) }

    fun onButtonClick(view: View) {
        start(LayoutDSLActivity::class.java)
    }

    fun onLaneClick(view: View) {
        start(LaneViewActivity::class.java)
    }

    fun onPerClick(view: View) {
        start(PercentActivity::class.java)
    }


}